package com.dpmc.service;
  
import java.util.HashMap;
import java.util.Map;

import javax.ejb.Stateless;

import com.common.util.ObjectUtils;
import com.core.service.AppBaseService; 
import com.dpmc.entity.*;  
/**
 * 渠道商管理
 */
@Stateless 
public class SVC_QDSGL  extends AppBaseService implements SVC_QDSGLRemote, SVC_QDSGLLocal {

	@Override
	public Map ADD_JBXX(Map param) {
		TB_QDSGL_JBXX jbxx =  ObjectUtils.mapToJavaBean(param, TB_QDSGL_JBXX.class);
		jbxx.setID(jbxx.uuid());
		jbxx.setCREATE_TIME(getOpTime(param));
		jbxx.setOP_ITEM(getOpTime(param));
		jbxx.setOPID(getOpid(param) );   
		getJpaDao().save(jbxx); 
		
		Map USER=(Map)param.get("OBJECT_SYS_USER");
		if(USER!=null){
			copySysParam(param, USER);
			USER.put("INFO_ID", jbxx.getID()); 
			USER.put("INFO_TYPE", "TB_QDSGL_JBXX"); 
			USER.put("INFO_NAME", jbxx.getQDSMC());  

			getServiceInterface().doService("RMServiceBean", "addSysUser", USER); 
		}  
		Map yhzh=(Map)param.get("OBJECT_TB_YHZH");
		if(yhzh!=null){
			TB_YHZH yhzh_vo =  ObjectUtils.mapToJavaBean(yhzh, TB_YHZH.class);
			yhzh_vo.setID(yhzh_vo.uuid());
			yhzh_vo.setGLLX("TB_QDSGL_JBXX");
			yhzh_vo.setGLID(jbxx.getID());
			yhzh_vo.setCREATE_TIME(getOpTime(param));
			yhzh_vo.setOP_ITEM(getOpTime(param));
			yhzh_vo.setOPID(getOpid(param) );  
			getJpaDao().save(yhzh_vo);
		} 
		
		//商户财务账户
	    Map cwzh = new HashMap();
		cwzh.put("ZHLX", "TB_QDSGL_JBXX");
		cwzh.put("GLID", jbxx.getID()); 
		copySysParam(param,cwzh);
		getServiceInterface().doService("SVC_CWGL", "ADD_ZH", cwzh);
		
		Map retMap =ObjectUtils.javaBeanToMap(jbxx);  
		return retMap;
	}

	@Override
	public Map UPD_JBXX(Map param) {
		System.out.println("param="+param);
		TB_QDSGL_JBXX jbxx =  ObjectUtils.mapToJavaBean(param, TB_QDSGL_JBXX.class);
	  
		jbxx.setOP_ITEM(getOpTime(param));
		jbxx.setOPID(getOpid(param));   
		
		TB_QDSGL_JBXX jbxx_po =getJpaDao().find(TB_QDSGL_JBXX.class, jbxx.getID());
		
		ObjectUtils.copyJavaBeanToBean(jbxx, jbxx_po, "CREATE_TIME");
		getJpaDao().update(jbxx_po);
		
		
		Map yhzh=(Map)param.get("OBJECT_TB_YHZH");
		if(yhzh!=null){
			TB_YHZH yhzh_vo =  ObjectUtils.mapToJavaBean(yhzh, TB_YHZH.class);
			yhzh_vo.setOP_ITEM(getOpTime(param));
			yhzh_vo.setOPID(getOpid(param) ); 
			if(yhzh_vo.getID()==null){
				yhzh_vo.setID(yhzh_vo.uuid());
				yhzh_vo.setGLLX("TB_QDSGL_JBXX");
				yhzh_vo.setGLID(jbxx.getID());
				yhzh_vo.setCREATE_TIME(getOpTime(param)); 
				getJpaDao().save(yhzh_vo);
			} else{
				TB_YHZH yhzh_po =getJpaDao().find(TB_YHZH.class, yhzh_vo.getID());  
				ObjectUtils.copyJavaBeanToBean(yhzh_vo, yhzh_po, "ID","CREATE_TIME","GLLX","GLID"); 
				getJpaDao().update(yhzh_po);
			}
		} 
		
		Map USER=(Map)param.get("OBJECT_SYS_USER");
		if(USER!=null){
			copySysParam(param, USER);
			USER.put("INFO_ID", jbxx.getID()); 
			USER.put("INFO_TYPE", "TB_QDSGL_JBXX");   
			USER.put("INFO_NAME", jbxx.getQDSMC());   
			if(USER.get("ID")!=null){
				getServiceInterface().doService("RMServiceBean", "updateSysUser", USER); 
			}else{
				getServiceInterface().doService("RMServiceBean", "addSysUser", USER); 
			} 
		}  
		
		Map retMap =ObjectUtils.javaBeanToMap(jbxx_po); 
		return retMap;
	}

	@Override
	public void DEL_JBXX(Map param) { 
		String id = ObjectUtils.getMapValue(param, "ID", String.class);
		
		TB_QDSGL_JBXX jbxx_po =getJpaDao().find(TB_QDSGL_JBXX.class, id );
		jbxx_po.setOP_ITEM(getOpTime(param));
		jbxx_po.setOPID(getOpid(param));
		jbxx_po.setSTATUS(TB_QDSGL_JBXX.STATUS_DEAD);
		getJpaDao().update(jbxx_po); 
	}
 
}
